<?php

$m = new MongoClient('mongodb://ftp.giemiebier.nl');

require_once('rb.php');
R::setup('mysql:host=ftp.giemiebier.nl:3306;dbname=personify', 'school', 'admin123');

function getUserById($id) {
    $user = R::findOne("users", "id=?", array($id));
    return $user;
}

$db = $m->chatdb;
$message = $db->message;
$now = date("Y-m-d H:i:s");
$user = getUserById($_POST['sender_id']);
$data = array("chat_id" => $_POST['chat_id'], "message" => $_POST['message'], "sender_id" => $_POST['sender_id'],"sender_email" => $user->emailaddress,"time_sent" => $now);
$message->insert($data);

?>


